// JORGE FERNANDO GOMEZ
// 1259371
// 189631
// LEC A1
// MARTIN MÜLLER
// D02
// YANG LIU


#ifndef UTIL_C
#define UTIL_C 1

#include <stdbool.h>
#include <time.h>

#define MAX_DEBUG           8

/* Struct to maintain open streams. */
struct Streams {
    char stream_type;   /* 'f' or 'p'. */
    FILE ** streamptr;
    struct Streams * next;
};


/* FUNCTION PROTOTYPES. */
/* Please see ./util.c for more information. */


/*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
 *                                                                           *
 *                              Management                                   *
 *                                                                           *
 *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*/

    /* Opens a new I/O stream and returns the pointer to it. */
    FILE* openStream ( const char * filename, char type, const char * mode );

    /* Opens a stream for debuggin. */
    FILE* openLogStream ( const char * filename,
                          char type, const char * mode );

    /* Adds a stream to a stream list. */
    void addStream ( void * stream, char type, bool issketchpad );

    /* Returns the 'main' output pipe (sketchpad). */
    FILE** getOutputStream ( void );

    /* Returns debug stream FILE pointer. */
    FILE* getLogStream ( void );

    /* Closes open streams. */
    void closeStreams ( void );

    /* Terminate the program and print an error. */
    void killim ( int numLine );


                /* + * + * + * + * + * + * + * + * + * + */



/*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
 *                                                                           *
 *                             General Tools                                 *
 *                                                                           *
 *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*/

    /* Finds number parameters on an alphanumeric string. */
    double* getDoubles ( char * string, int blocks2skip, int count );

    /* Same as getDoubles(), but with longs. */
    long* getLongs ( char * string, int blocks2skip, int count );

    /* Creates a substring from string and returns a pointer to it. */
    char* substr (const char * string, int offset, int length);

    /* Removes trailing whitespace (from isspace()) from lineString. */
    void chompim (char * lineString);

    /* Exponentiates a number. */
    long Exp ( int base, int exponent );


/* Prototypes for popen() and pclose() */
FILE * popen (const char *, const char *);
int pclose (FILE *);

#endif /* end of include guard: UTIL_C */
